<template>
  <component :is="tag" ref="wrapEl"/>
</template>

<script setup>
import {onMounted, ref} from 'vue'
import JsBarcode from "jsbarcode";

defineOptions({name: 'MBarcode'})
const props = defineProps({

  tag: {
    type: String,
    default: 'canvas'
  },
  // 条形码类型
  type: {
    type: String,
    default: 'CODE128'
  },
  text: {
    type: String,
    default: null
  },
  options: {
    type: Object,
    default: () => ({})
  }

})
const wrapEl = ref()
onMounted(() => {
  const opt = Object.assign(props.options, {format: props.type})
  JsBarcode(wrapEl.value, props.text, opt)
})
</script>


<style scoped lang="scss">

</style>